package com.rui.study.algorithm.L_深入拆解JVM_InvokeDynamic;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2018-12-14 11:10
 **/
public class FooV9 {

    public static void target(int i) {

    }

    static final MethodHandle mh;

    static {
        try {
            MethodHandles.Lookup l = MethodHandles.lookup();
            MethodType t = MethodType.methodType(void.class, int.class);
            mh = l.findStatic(FooV9.class, "target", t);
        } catch (Exception e) {
           throw new RuntimeException();
        }
    }

    public static void main(String[] args) throws Throwable {

        long curent = System.currentTimeMillis();
        for (int i = 1; i <= 2_000_000_000; i++) {
            if (i % 100_000_000 == 0) {
                long temp = System.currentTimeMillis();
                System.out.println(temp - curent);
                curent = temp;
            }
            mh.invokeExact(128);
        }
    }
}
